home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 13 / 013.d81 / dos #34 < prev    next >
Text File  |  2022-08-26  |  4KB  |  184 lines

  1. ======================================
  2.        DOS & Don'ts -- Part 34
  3.  
  4.        by James Gregory Weiler
  5. ======================================
  6.  
  7. Part C: The BAM in depth
  8.  
  9. (See map 2a: track bit maps)
  10.  
  11.   Now, here's how we can use just four
  12.  
  13. bytes of the BAM to represent a whole
  14.  
  15. track containing up to 5376 bytes.
  16.  
  17. Let's look at just one set of four
  18.  
  19. bytes, the four that represent track
  20.  
  21. one.  Remember, numbers that we
  22.  
  23. precede with a dollar sign are HEX
  24.  
  25. (base 16) numbers.
  26.  
  27. Byte 4   Byte 7   Byte 6   Byte 5
  28.    $15      $1F      $FF      $FF
  29.  
  30.   Byte four is the block counter and
  31.  
  32. bytes five through seven are the track
  33.  
  34. bit map.  We already know that track 1
  35.  
  36. has 21 blocks in it, blocks 0 through
  37.  
  38. 20.  The number in byte 4 tells us how
  39.  
  40. many blocks are unused on track 1.
  41.  
  42. $15 (hex) is 21 decimal -- so 21 of
  43.  
  44. the 21 blocks in track 1 are unused.
  45.  
  46. Which twenty-one aren't used?  That's
  47.  
  48. what the other three bytes tell us.
  49.  
  50. Each bit in each byte represents one
  51.  
  52. block, so let's print out bytes five
  53.  
  54. through seven in binary so we can see
  55.  
  56. all the bits.
  57.  
  58.  Byte 7:$1F  Byte 6:$FF  Byte 5:$FF
  59.    00011111    11111111    11111111
  60.  
  61.   Now, starting at the right, and
  62.  
  63. starting with zero (because blocks on
  64.  
  65. a track start with number zero), count
  66.  
  67. the ones.  There are 21, numbered zero
  68.  
  69. through twenty.  One for each block on
  70.  
  71. the track.
  72.  
  73.   Whenever we SAVE a program, DOS
  74.  
  75. keeps track of which blocks the
  76.  
  77. program was saved in by changing the
  78.  
  79. appropriate ones to zeros in the
  80.  
  81. track bit maps for the tracks where
  82.  
  83. the program was saved.  That sound
  84.  
  85. like gobbledygook to you, too?  Here's
  86.  
  87. an example.
  88.  
  89.   Let's say you saved a program that
  90.  
  91. is two blocks long and DOS decided to
  92.  
  93. put it on track 0 block 3, and track 0
  94.  
  95. block 6.
  96.  
  97.   Besides placing the program on track
  98.  
  99. zero, DOS has to update the track zero
  100.  
  101. bit map.  Since it used blocks 3 and
  102.  
  103. 6, it has to change the bits that
  104.  
  105. represent those blocks from ones to
  106.  
  107. zeros.  Blocks 3 and 6 are represented
  108.  
  109. by the third and sixth bits from the
  110.  
  111. right in our charts.  DOS also needs
  112.  
  113. to subtract two from the block counter
  114.  
  115. for track one, because it used two of
  116.  
  117. the available blocks.  Here's a chart:
  118.  
  119. --------------------------------------
  120.  
  121. TRACK BIT MAP OF TRACK ZERO
  122.  
  123.  byte 4   byte 7   byte 6   byte 5
  124.  {CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}
  125. BEFORE SAVING
  126.  
  127.      $15      $1F      $FF      $FF
  128. 00010101 00011111 11111111 11111111
  129.  
  130. AFTER SAVING
  131.  
  132.      $13      $1F      $FF      $B7
  133. 00010011 00011111 11111111 10110111
  134.  
  135. --------------------------------------
  136.  
  137.   Map 2a shows you what the track
  138.  
  139. bit maps look like on a disk that
  140.  
  141. has no files on it.  Bytes zero and
  142.  
  143. three of the track bit maps are
  144.  
  145. different from track to track because
  146.  
  147. different tracks have different
  148.  
  149. numbers of blocks.
  150.  
  151. ======================================
  152.  
  153. Map 2a: representative track bit map.
  154.  
  155. byte    description
  156. --------------------------------------
  157.   0  Free Block Counter
  158.   1  Map of sectors 0-7
  159.   2  Map of sectors 8-15
  160.   3  Map of sectors 16-20
  161. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  162.  
  163. Track bit maps for empty tracks:
  164.  
  165.     byte 3   byte 2   byte 1   byte 0
  166.     ------- -------- -------- --------
  167. tracks
  168.  1-17   $1F      $FF      $FF      $15
  169.    00011111 11111111 11111111 00010101
  170.  
  171. 18-24   $07      $FF      $FF      $13
  172.    00000111 11111111 11111111 00010011
  173.  
  174. 25-30   $03      $FF      $FF      $12
  175.    00000011 11111111 11111111 00010010
  176.  
  177. 31-35   $01      $FF      $FF      $11
  178.    00000001 11111111 11111111 00010001
  179.  
  180.       21111 11111198 76543210   block
  181.       09876 543210        represented
  182.  
  183. =======< continued in Part 35 >=======
  184.